<#include "/macro.include"/>
<#assign className = table.className>   
<#assign classNameFirstLower = className?uncap_first> 
<#assign classNameLowerCase = className?lower_case> 
package ${basepackage}.web;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.gt.xmall.model.GtdContext;
import com.gt.xmall.service.GtdContextService;
import com.gt.xmall.web.BaseController;

import ${basepackage}.model.${className};
import ${basepackage}.service.${className}Service;

@Controller
@RequestMapping(value = "/gtd/${classNameLowerCase}/")
public class ${className}Controller extends BaseController {
	
	@Autowired
	private ${className}Service ${classNameFirstLower}Service;
	
	@RequestMapping(value = "list",method = RequestMethod.GET)
	public String list(Model model){
		List<${className}> list = ${classNameFirstLower}Service.get${className}s();
		model.addAttribute("${classNameFirstLower}List", list);
		return "gtd/${classNameFirstLower}List";
	}
	@RequestMapping(value = "show/{id}",method = RequestMethod.GET)
	public String show(@PathVariable("id") String id,Model model){
		${className} ${classNameFirstLower} =${classNameFirstLower}Service.get${className}(new Long(id));
		model.addAttribute("${classNameFirstLower}", ${classNameFirstLower});
		return "gtd/${classNameFirstLower}Form";
		
	}
	@RequestMapping(value="save",method = RequestMethod.POST)
	public String save(@Valid ${className} ${classNameFirstLower},RedirectAttributes redirectAttributes){
		${classNameFirstLower} = ${classNameFirstLower}Service.save${className}(${classNameFirstLower});
//		redirectAttributes.addAttribute("gtdContext", gtdContext);
		return "redirect:/gtd/${classNameLowerCase}/show/"+${classNameFirstLower}.getId();
	} 
	@RequestMapping(value = "new",method = RequestMethod.GET)
	public String blankForm(){
		return "gtd/${classNameFirstLower}Form";
	}
	
	@RequestMapping(value = "delete/{id}",method = RequestMethod.GET)
	public String delete(@PathVariable("id") String id,Model model){
		${classNameFirstLower}Service.delete${className}(new Long(id));
		
		return "redirect:/gtd/${classNameLowerCase}/list";
		
	}
	
}